package com.google.code.qsecurity.client.util;

import java.util.Date;

import com.google.gwt.user.client.Cookies;

public class CookieUtil {
	private static final String SESSION_COOKIE_NAME = "QSESSION";
	private static final String USER_COOKIE_NAME = "QUSER";
	
	public static void init() {
		Cookies.setUriEncode(false);
	}
	
	public static String getSessionId() {
		return Cookies.getCookie(SESSION_COOKIE_NAME);
	}
	
	public static String getUserEmail() {
		return Cookies.getCookie(USER_COOKIE_NAME);
	}
	
	public static void setSessionCookie(String sessionId, Date expiration) {
		if (Cookies.isCookieEnabled()) {
			Cookies.setCookie(SESSION_COOKIE_NAME, sessionId, expiration);
		}
	}
	
	public static void setUserCookie(String email, Date expiration) {
		if (Cookies.isCookieEnabled()) {
			Cookies.setCookie(USER_COOKIE_NAME, email, expiration);
		}
	}
	
	public static void setAllCookies(String sessionId, String email, Date expiration) {
		if (Cookies.isCookieEnabled()) {
			setSessionCookie(sessionId, expiration);
			setUserCookie(email, expiration);
		}
	}
	
}
